<?php

/**
 * MVM_MALL 网上商店系统  品牌
 * ============================================================================
 * 版权所有 (C) 2007-2010 www.mvmmall.com，并保留所有权利。
 * 网站地址: http://www.mvmmall.com
 * ----------------------------------------------------------------------------
 * 这是一个免费开源的软件；这意味着您可以在不用于商业目的的前提下对程序代码
 * 进行修改、使用和再发布。
 * ============================================================================
 * $Author:  www.mvmmall.com  $
 * $Date: 2008-06-27 $
 * $Id: brand.php  www.mvmmall.com$
 * ---------------------------------------------
*/

require_once './include/common.inc.php';
require_once MVMMALL_ROOT.'./include/pager.class.php';
if ($action == 'list') {
	$total_count = $db->counter("{$tablepre}brand_table");
	$page        = $page ? (int)$page : 1;
	$list_num    = 20;
	$rowset      = new Pager($total_count,$list_num,$page);
	$from_record = $rowset->_offset();
	$result      = $db->query("SELECT id,brandname,logo,weburl,train FROM `{$tablepre}brand_table` ORDER BY `train` LIMIT $from_record,$list_num");
	while($list  = $db->fetch_array($result)) {
		$list['title'] = $list['brandname'];
		$list['url']   = $rewrite == 1 ? "brand-view-$list[id].html" : "brand.php?action=view&id=$list[id]" ;
		$list['photo'] = $list[logo]=='' ? $imgpath.'/brand.gif' : $list[logo];
		$brand[]       = $list;
	}
	if ($rewrite == 1) {
		$baseurl = str_replace('1.html','',GetBaseUrl('brand',$action));
		$exc='.html';
	} else{
		$baseurl = GetBaseUrl('brand',$action).'&page=';
	}
	$page_list     = $rowset->link($baseurl, $exc);
	$navigation    = make_navigation($lang['brand_show'],$baseurl.$page.$exc);//导航
	$mm_mall_title =  $lang['brand_show']; //标题
	require_once MVMMALL_ROOT.'header.php';
	require_once template('brand_list');
	footer();
}
elseif ($action == 'view' && is_numeric($id)) {
	$serch_sql   = false;
	$serch_sql   = "WHERE goods_brand='$id' AND goods_class = '0' AND upv = '1' AND up_date<='$m_now_time'";
	$total_count = $db->counter("{$tablepre}goods_table","$serch_sql");
	$page        = $page ? (int)$page : 1;
	$list_num    = $mm_limit_list;//后台可控制显示数量
	$rowset      = new Pager($total_count,$list_num,$page);
	$from_record = $rowset->_offset();
	$query = "SELECT goods_brand,goods_hit,goods_file1,goods_sale_price,goods_market_price,goods_name,uid,goods_category,
		            goods_status,goods_class,upv,up_date,goods_rank,goods_point,goods_addoption1,
		            goods_addoption2,goods_addoption3,goods_addoption4 
		            FROM `{$tablepre}goods_table` $serch_sql ORDER BY `uid` DESC LIMIT $from_record,$list_num";
	$result = $db->query($query);
	while($list =  $db->fetch_array($result)) {
		$goods[]=goods_array($list);
	}
	if ($rewrite == 1) {
		$baseurl ="brand-view-$id-" ;
		$exc='.html';
	} else{
		$baseurl = "brand.php?action=view&id=$id&page=";
	}
	$page_list = $rowset->link($baseurl,$exc);
	$id = (int)$id;
	$brand = $db->get_one("SELECT * FROM `{$tablepre}brand_table` WHERE id='$id'");
	$mm_mall_title = $brand['brandname']; //标题
	$brand['keywords'] && $mm_keywords        = $brand['keywords']; //关键字
	$brand['brief']  && $mm_description       = cut_str($brand['brief'],255); //描述
	$navigation = make_navigation($lang['brand_show'],$rewrite == 1 ? "brand-view-$id.html" : "brand.php?action=view&id=$id");//导航
    require_once MVMMALL_ROOT.'header.php';
	include template('brand_view');
	footer();
} else {
	admin_msg('pass_worng');
}
